const wxHttpHandler = require('../../utils/wxHttpHandler.js');
const api = require('../../APIConfig/apiConfig.js');
const QQMapWX = require('../../utils/qqmap-wx-jssdk.js')
const WSCoordinate = require('../../utils/WSCoordinate.js');
var app = getApp();
var qqMapSDK;


Page({
  data: {
    vehicleId: -1,
    details: null, //详情
    loaction: ''
  },

  onLoad: function (options) {
    let that = this
    this.setData({
      vehicleId: options.vehicleId
    })
    this.getRealtimeVehicleTemperatureMonitorInfo()
    qqMapSDK = new QQMapWX({
      key: 'EWDBZ-3BZ36-BDGSG-MMQHU-KW7OK-FDBMA'
    })
  },

  onShow: function () {},

  //运输监控-车辆实时温控详情
  getRealtimeVehicleTemperatureMonitorInfo: function () {
    let data = {
      vehicleId:this.data.vehicleId
    }
    const that = this
    wx.showLoading()
    wxHttpHandler({
      type: 'get',
      path: api.getRealtimeVehicleTemperatureMonitorInfo,
      data: data,
      fn: function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          if (res.data != null) {
            that.setData({
              details: res.data
            })
            var point = WSCoordinate.transformFromWGSToGCJ(that.data.details.latitude, that.data.details.longitude)
            qqMapSDK.reverseGeocoder({
              location: {
                latitude: point.latitude,
                longitude: point.longitude
              },
              success: function (addressRes) {
                console.log(addressRes.result.address)
                that.setData({
                  loation: addressRes.result.address,
                })
              }
            })

          }
        } else {
          wx.showToast({
            title: res.desc,
            icon: 'none',
            duration: 1500,
            mask: true
          });
        }
      }

    })
  },

})